<?php
declare (strict_types=1);

namespace app\course\model\courseware\admin;

use app\common\logic\Attach;
use app\common\model\BaseModel;
use app\course\logic\base\admin\Course;
use app\course\model\base\CourseWareRecord;

/**
 * Class Courseware
 *
 * @package app\course\model\courseware\admin
 */
class Courseware extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'course_courseware';

    /**
     * 设置自动写入时间
     *
     * @var boolean
     */
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;
    /**
     * 时间显示格式
     *
     * @var string
     */
    protected $dateFormat = 'Y-m-d H:i';

    /**
     * 定义字段类型
     *
     * @var array
     */
    protected $type = [
        'id' => 'integer',
    ];

    /**
     * 课程信息
     *
     * @return \think\model\relation\BelongsTo
     */
    public function course()
    {
        return $this->belongsTo(Course::class, 'course_id')->bind(['course_title' => 'title']);
    }

    /**
     * 课件附件信息
     *
     * @return \think\model\relation\BelongsTo
     */
    public function attach()
    {
        return $this->belongsTo(Attach::class, 'attach_id', 'id')->bind(['attach_title' => 'filename']);
    }

    /**
     * 课件下载记录信息
     *
     * @return \think\model\relation\BelongsTo
     */
    public function record()
    {
        return $this->belongsTo(CourseWareRecord::class, 'attach_id', 'ware_id')->bind(['download_count' => 'count']);
    }
}